#!/bin/bash
set -e

function info() {
echo Usage: `basename $0` '[-p out_prefix]'

cat <<info

info

exit 65

}

while getopts ":p:" opts
do
case $opts in
p) out_prefix=$OPTARG;;
\?) info;;
esac
done
shift $(($OPTIND - 1))

# test $# -lt 1 & info


#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------

# test ! -s $out_prefix.names.txt & echo 1.cn_simu.txt

Rscript ${tools_path}/script/simu_cn_states.r

rename 1 $out_prefix 1.cn_states_simu.pdf

for i in $(seq 30); do
echo $i.cn_simu.txt cn_simu 1 $out_prefix > $out_prefix.cn_simu.name.txt
Rscript ${tools_path}/script/lorenz_cnv.r --args $out_prefix.cn_simu.name.txt
mv 1.lorenz.pdf $i.lorenz.simu_cn.pdf
rm $i.cn_simu.txt

pdfs="$pdfs $i.lorenz.simu_cn.pdf"
done

run.sh cpdf -merge $pdfs -o $out_prefix.lorenz.cn_simu.pdf

rm *.lorenz.simu_cn.pdf

bak.sh -ttes $out_prefix.cn_states_simu.pdf $out_prefix.lorenz.cn_simu.pdf


